"""
Common library for ERS tests with Robot Framework

Check Data Type added by Bharath on 03/07/2012
"""

import sys

class CommonERSLibrary:

    def amountStringToDecimalValue(self, amountString, decimalSeparator=',', thousandSeparator='.', currency='EUR'):
        """ Amount String To Decimal Value
            -- Takes a String with a formatted amount (value + currency) and transforms
               it into a real decimal value.
               
            Input:
                amountString      - The String to be re-formatted
                decimalSeparator  - Character that separates the integers from the decimals,
                                    by default set to ","
                thousandSeparator - Character that separates each three digits of the amount,
                                    by default set to "."
                currency          - Currency code used in amount string, default is 'EUR'.
            Output:
                decimalAmount     - The decimal representation of the inputted amount.
        """

        amount = amountString.rstrip(currency)
        decimalAmount = amount.replace(thousandSeparator,'')
        decimalAmount = decimalAmount.replace(decimalSeparator,'.')

        return decimalAmount
    
    
def Check_Data_Type(data):
     """
     Returns data type of parsed paarameter. Returned value will be 3 characters representing corresponding data type
     
     Examples:
     Integer value will return int.
     Long Integer will return lon.
     String will return str.
     
     Important: Unicode data type will be decoded
     """
     
     print "Passed Parameter is ", data
     resulttype = str(type(data))
     print resulttype
     dataType = resulttype[7:10]
     if(dataType == "uni"):
           resulttype = str(type(data.encode()))
           dataType = resulttype[7:10]
           result = dataType
     elif (dataType == "int"):
           result = dataType
     elif (dataType == "lon"):
           result = dataType
     elif (dataType == "str"):
           result = dataType      
     else:
           result = "Unknown Type"
     return result



    # Tests
    # print amountStringToDecimalValue('1.305,50 EUR')
